﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Core.Entities;
using Library.Extensions;

namespace Core.Queries
{
    public class ItemQuery : BaseQuery<Item>
    {
        public int? ArticleID { get; set; }
        public string Message { get; set; }

        public override Expression<Func<Item, bool>> ToExpression()
        {
            Expression<Func<Item, bool>> predicate = x => true;

            if (ArticleID.HasValue)
                predicate = x => x.ArticleID == ArticleID;

            if (!string.IsNullOrWhiteSpace(Message))
                predicate = x => x.Message.StartsWith(Message);

            return predicate;
        }
    }
}